package gsw.demo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;

import gsw.demo.bean.Friend;
import gsw.eventbus.R;
import gsw.tool.eventbus.core.Hermes;
import gsw.tool.eventbus.eventbus.EventBus;
import gsw.tool.eventbus.eventbus.Subscribe;
import gsw.tool.eventbus.eventbus.ThreadMode;

public class MainActivity extends AppCompatActivity {

    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = findViewById(R.id.text_content);

        Hermes.getDefault().initEventBus(this);
        EventBus.getInstance().register(this);
    }

    public void jump(View view) {
        startActivity(new Intent(this, SecondActivity.class));
    }

    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onMessageEvent(Friend event) {
        Log.d("Test2008", new Gson().toJson(event));
        textView.setText(new Gson().toJson(event));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getInstance().unRegister(this);
    }
}
